import numpy as np
import os

np.set_printoptions(precision=3, suppress=True)

mean_list = []
std_list = []


def mean_std(root_path='envs_number_64/processes_4'):
    solved_number = 0
    all_episodes = []
    for file in os.listdir(root_path):
        file_path = os.path.join(root_path, file)
        content = open(file_path).readlines()
        # print("第", file[:-4], "个文件。", content[-2], end='')
        if "Task solved" in content[-3]:
            solved_number += 1
            all_episodes.append(float(content[-1]))

    mean_list.append(np.mean(all_episodes))
    std_list.append(np.std(all_episodes))
    print("mean:%13.4f" % np.mean(all_episodes), "      std:%13.4f" % np.std(all_episodes),
          "共解决任务数: %3d" % solved_number)


for i in [8, 64, 128, 256, 512, 1024, 2048, 4096, 8192]:
    for j in [4]:
        root_path = "envs_number_%d/processes_%d" % (i, j)
        print("%30s:" % root_path, end=" " * 5)
        mean_std(root_path)

print('\n')

for i in [2048, 4096, 8192]:
    for j in [1, 4, 8, 12, 16]:
        if i != 4096 and (j == 12 or j==16):
            continue
        root_path = "envs_number_%d/processes_%d" % (i, j)
        print("%30s:" % root_path, end=" " * 5)
        mean_std(root_path)
    print('\n')
